- recipients = Entity.where(id: Parcel.pluck(:recipient_id).compact.uniq)
- senders = Entity.where(id: Parcel.pluck(:sender_id).compact.uniq)
- responsibles = User.where(id: Parcel.select(:responsible_id).distinct)
= kujaku do |k|
  - k.text
  - k.helper do
    = journal_period_crit(label: Parcel.human_attribute_name(:planned_at))
  - if recipients.any?
    - k.helper do
      %label= Parcel.human_attribute_name(:recipient)
      = select_tag(:recipient_id, options_for_select([[]] + recipients.order(:name).collect{|u| [u.name, u.id]}, params[:recipient_id]))
  - if senders.any?
    - k.helper do
      %label= Parcel.human_attribute_name(:sender)
      = select_tag(:sender_id, options_for_select([[]] + senders.order(:name).collect{|u| [u.name, u.id]}, params[:sender_id]))

  - if responsibles.any?
    - k.helper do
      %label= Parcel.human_attribute_name(:responsible)
      = select_tag(:responsible_id, options_for_select([[]] +  responsibles.map{|u| [u.label, u.id]}, params[:responsible_id].to_i))

  -# - senders = Entity.all
  -# - if senders.any?
  -#   - k.helper do
  -#     %label= Parcel.human_attribute_name(:sender)
  -#     = select_tag(:sender_id, options_for_select([[]] + senders.order(:name).collect{|u| [u.name, u.id]}, params[:sender_id]))
  -# - transporters = Entity.all
  -# - if transporters.any?
  -#   - k.helper do
  -#     %label= Parcel.human_attribute_name(:transporter)
  -#     = select_tag(:transporter_id, options_for_select([[]] + transporters.order(:name).collect{|u| [u.name, u.id]}, params[:transporter_id]))
  - k.choice *([[:all.tl, :all]] + resource_model.nature.values.map{ |s| [s.l, s] }), name: :nature, label: Parcel.human_attribute_name(:nature)
  - k.choice *([[:all.tl, :all]] + resource_model.delivery_mode.values.map{ |s| [s.l, s] }), name: :delivery_mode, label: Parcel.human_attribute_name(:delivery_mode)
  - k.choice *([[:all.tl, :all], [:invoiced.tl, :invoiced], [:uninvoiced.tl, :uninvoiced]]), name: :invoice_status, label: :invoice_status.tl

- main_toolbar do |t|
  = t.new params: { nature: :incoming, redirect: nil }, label: :new_incoming_parcel.tl
  = t.new params: { nature: :outgoing, redirect: nil }, label: :new_outgoing_parcel.tl

= main_list
